<?php

class DefaultController extends Controller {

    public function actionIndex() {
        
        $this->render('index');
    }
    
    public function actionFlickr(){
        $model=new User('userRegister');
        $model->autoFill();
        $this->performAjaxValidation($model);
        
        $params = Yii::app()->request->getParam(get_class($model));
        if($params){
            $model->image_ = CUploadedFile::getInstances($model, 'image_');

            $result = Yii::app()->flickr->upload($model->image_[0]->tempName, $model->image_[0]->name);
            if($result){
                echo 'info: ';
                $p=Yii::app()->flickr->getPhotoInfo();
                print_r($p);
               
                
                echo '<br /><br /><br />';
                echo 'url: ';
                echo Yii::app()->flickr->getPhotoUrl($p);
                
                echo '<br /><br /><br />';
                echo 'size: ';
                $p=Yii::app()->flickr->getPhotoSizes();
                var_dump($p);
                
            }else{
                Yii::app()->flickr->getErrors();
            }
        }
        
        $this->render('flickr', array(
            'user' => $model,
            'formConfig' => array(
                'id' => $this->formId,
                'enableAjaxValidation' => true,
                'enableClientValidation' => true,
                'clientOptions' => array(
                    'validateOnSubmit' => true,
                ),
                'htmlOptions' => array(
                    'enctype' => 'multipart/form-data',
                ),
                'focus' => array($model, 'firstName_'),
            ),
        ));
    }
    
    public function actionGeocoding(){
        $geo=new Geocoder();
        $geo->address='31, LORONG UDANG KETAK 3, TAMAN SRI SEGAMBUT, KUALA LUMPUR, 52000, Malaysia';
        $geo->address='307, 3Rd Floor, Summit Subang Usj, Persiaran Kewajipan, Usj 1, Subang Jaya, Selangor, 47600';
        $geo->components='country:MY';
        $geo->getResponse();
        print_r($geo->data);
        
        echo '<br/><br/>';
        print_r($geo->addressComponents[0]);
        
        echo '<br/><br/>';
        echo $geo->get('latitude');
        echo '<br/><br/>';
        echo $geo->get('longitude');
        echo '<br/><br/>';
        echo $geo->get('formatted_address');
        
        echo '<br/><br/>';
        echo $geo->get(Geocoder::STATE);
        
        echo '<br/><br/>';
        echo $geo->get('locality');
        echo '<br/><br/>';
        echo $geo->get('COUNTRY');
        
        echo $geo->get('postal_code');
        
        
    }        
}